package coder.nav.utils;

import java.io.IOException;
import java.sql.*;
import java.util.*;

public class SqlUtils {
    // 数据库地址
    static String MYSQL_HOST = "restore.saas-db-publicqa.mysql.internal.weimob.com";
    // 数据库端口
    static String MYSQL_PORT = "3306";
    // 数据库账号
    static String MYSQL_USERNAME = "xmn_qa_rw";
    // 数据库密码
    static String MYSQL_PASSWORD = "sfw7GQBfw5mjd4yp60TF";
    // 数据库
    static String MYSQL_DATABASE = "xmn_project";
    // 项目根目录
    static String ROOT_PATH = "E:\\JavaProject\\xmn-product-system";
    // 数据源
    static String DATA_SOURCE = "xmnSystemDataSource";
    // 需要生成的实体
    static String[] BEANS = {
            // "BO",
            // "VO",
            // "AO",
            // "DTO",
            "Entity",
            "Mapper",
            "Service",
            // "Associate",
            // "WebConvert",
            // "ServerConvert",
    };
    // 需要生成的表
    static String[] TABLES = {
            "xmn_hotel_product_order_price",
    };

    public static void main(String[] args) throws Exception {
        createXmnJavaBean();
    }

    // 字段类型映射
    static Map<String, String> TYPE_MAP = new HashMap<>();
    static {
        TYPE_MAP.put("INT", "Integer");
        TYPE_MAP.put("BIT", "Integer");
        TYPE_MAP.put("TINYINT", "Integer");
        TYPE_MAP.put("SMALLINT", "Integer");
        TYPE_MAP.put("BIGINT", "Long");
        TYPE_MAP.put("FLOAT", "Float");
        TYPE_MAP.put("DOUBLE", "DOUBLE");
        TYPE_MAP.put("DECIMAL", "BigDecimal");
        TYPE_MAP.put("CHAR", "String");
        TYPE_MAP.put("VARCHAR", "String");
        TYPE_MAP.put("JSON", "String");
        TYPE_MAP.put("TEXT", "String");
        TYPE_MAP.put("LONGTEXT", "String");
        TYPE_MAP.put("DATETIME", "Date");
    }

    /**
     * 连接数据库
     */
    static Connection connection;
    static {
        String url = "jdbc:mysql://" + MYSQL_HOST + ":" + MYSQL_PORT + "/" + MYSQL_DATABASE;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection = DriverManager.getConnection(url, MYSQL_USERNAME, MYSQL_PASSWORD);
        } catch (Exception e) {
            throw new RuntimeException("数据库连接失败");
        }
    }

    /**
     * 表字段实体
     */
    static class ColumnItem {
        public String column;
        public String type;
        public String comment;

        public ColumnItem(String column, String type, String comment) {
            this.column = column;
            this.type = type;
            this.comment = comment;
        }
    }
    
    /**
     * 当前表参数
     */
    static String ROOT_PATH_INTERFACE;
    static String ROOT_PATH_SERVICE;
    static String ROOT_PATH_WEB;
    static String ROOT_PACK;
    static String TABLE_NAME_LINE;
    static String TABLE_NAME_UPPER;
    static List<ColumnItem> TABLE_COLUMNS;
    
    /**
     * 生成向蜜鸟数据库实体
     */
    public static void createXmnJavaBean() throws SQLException {
        String project = ROOT_PATH.substring(ROOT_PATH.lastIndexOf("\\") + 1);
        project = project.replaceAll("-model", "");
        ROOT_PATH_INTERFACE = ROOT_PATH + "\\" + project + "-interface\\src\\main\\java\\com\\weimob\\" + project.replaceAll("-", "\\\\");
        ROOT_PATH_SERVICE = ROOT_PATH + "\\" + project + "-server\\src\\main\\java\\com\\weimob\\" + project.replaceAll("-", "\\\\");
        ROOT_PATH_WEB = ROOT_PATH + "\\" + project + "-web\\src\\main\\java\\com\\weimob\\" + project.replaceAll("-", "\\\\");
        ROOT_PACK = "com.weimob." + project.replaceAll("-", ".");
        // 解析所需生成的表
        DatabaseMetaData metaData = connection.getMetaData();
        Map<String, List<ColumnItem>> map = new HashMap<>();
        for(String table : TABLES) {
            ResultSet rs = metaData.getColumns(connection.getCatalog(), "%", table, "%");
            while (rs.next()) {
                // 字段名
                String column = rs.getString("COLUMN_NAME");
                // 字段类型
                String type = rs.getString("TYPE_NAME");
                type = type.split(" ")[0];
                // 字段注释
                String comment = rs.getString("REMARKS");

                if(!map.containsKey(table)) {
                    map.put(table, new LinkedList<>());
                }
                if("id".equals(column)) {
                    comment = "主键id";
                }
                map.get(table).add(new ColumnItem(column, type, comment));
            }
        }
        map.forEach((table, columns) -> {
            TABLE_COLUMNS = columns;
            TABLE_NAME_LINE = table;
            TABLE_NAME_UPPER = FileUtils.upperCaseName(FileUtils.lineToHump(table));
            try {
                List<String> beans = Arrays.asList(BEANS);
                if(beans.contains("BO")) createXmnBO();
                if(beans.contains("VO")) createXmnVO();
                if(beans.contains("AO")) createXmnAO();
                if(beans.contains("DTO")) createXmnDTO();
                if(beans.contains("Entity")) createXmnEntity();
                if(beans.contains("Mapper")) createXmnMapper();
                if(beans.contains("Service")) createXmnService();
                if(beans.contains("Associate")) createXmnAssociate();
                if(beans.contains("WebConvert")) createXmnWebConvert();
                if(beans.contains("ServerConvert")) createXmnServerConvert();
            } catch (IOException e) {
                throw new RuntimeException("生成 " + table + " 实体失败");
            }
        });
    }

    /**
     * 生成 BO
     */
    public static void createXmnBO() throws IOException {
        String database = MYSQL_DATABASE.replaceAll("_", "");
        String pack = ROOT_PACK;
        StringBuilder javaBean = new StringBuilder();
        // package
        javaBean.append("package ").append(pack).append(".model.").append(database).append(".bo").append(";\n\n");
        // import
        javaBean.append("import com.saas.xmn.system.base.model.base.bo.LogInTypeBO;\n")
                .append("import io.swagger.annotations.ApiModel;\n")
                .append("import io.swagger.annotations.ApiModelProperty;\n");
        javaBean.append("import lombok.Data;\n")
                .append("import java.io.Serializable;\n")
                .append("import java.util.Date;\n");
        for(ColumnItem item : TABLE_COLUMNS) {
            if("DECIMAL".equals(item.type)) {
                javaBean.append("import java.math.BigDecimal;\n");
            }
        }
        javaBean.append("\n");
        // class
        javaBean.append("@Data").append("\n")
                .append("public class ").append(TABLE_NAME_UPPER)
                .append("BO extends LogInTypeBO implements Serializable {").append("\n\n");
        // column
        for(ColumnItem item : TABLE_COLUMNS) {
            String type = TYPE_MAP.getOrDefault(item.type, "Untitled");
            if(item.column.endsWith("id") || item.column.endsWith("Id")) {
                type = "Long";
            }
            javaBean.append("\t/**\n").append("\t * ").append(item.comment).append("\n").append("\t */\n");
            javaBean.append("\t@ApiModelProperty(\"").append(item.comment).append("\")\n");
            javaBean.append("\tprivate ").append(type).append(" ").append(FileUtils.lineToHump(item.column)).append(";\n\n");
        }
        javaBean.append("}\n");
        FileUtils.createJavaFile(ROOT_PATH_INTERFACE, "model\\" + database + "\\bo", TABLE_NAME_UPPER, "BO", javaBean.toString());
    }

    /**
     * 生成 VO
     */
    public static void createXmnVO() throws IOException {
        String database = MYSQL_DATABASE.replaceAll("_", "");
        String pack = ROOT_PACK;
        StringBuilder javaBean = new StringBuilder();
        // package
        javaBean.append("package ").append(pack).append(".model.").append(database).append(".vo").append(";\n\n");
        // import
        javaBean.append("import io.swagger.annotations.ApiModelProperty;\n");
        javaBean.append("import lombok.Data;\n")
                .append("import java.io.Serializable;\n")
                .append("import java.util.Date;\n");
        for(ColumnItem item : TABLE_COLUMNS) {
            if("DECIMAL".equals(item.type)) {
                javaBean.append("import java.math.BigDecimal;\n");
            }
        }
        javaBean.append("\n");
        // class
        javaBean.append("@Data").append("\n")
                .append("public class ").append(TABLE_NAME_UPPER)
                .append("VO implements Serializable {").append("\n\n");
        // column
        for(ColumnItem item : TABLE_COLUMNS) {
            String type = TYPE_MAP.getOrDefault(item.type, "Untitled");
            if(item.column.endsWith("id") || item.column.endsWith("Id")) {
                type = "Long";
            }
            javaBean.append("\t/**\n").append("\t * ").append(item.comment).append("\n").append("\t */\n");
            javaBean.append("\t@ApiModelProperty(\"").append(item.comment).append("\")\n");
            javaBean.append("\tprivate ").append(type).append(" ").append(FileUtils.lineToHump(item.column)).append(";\n\n");
        }
        javaBean.append("}\n");
        FileUtils.createJavaFile(ROOT_PATH_INTERFACE, "model\\" + database + "\\vo", TABLE_NAME_UPPER, "VO", javaBean.toString());
    }

    /**
     * 生成 AO
     */
    public static void createXmnAO() throws IOException {
        String database = MYSQL_DATABASE.replaceAll("_", "");
        String pack = ROOT_PACK;
        StringBuilder javaBean = new StringBuilder();
        // package
        javaBean.append("package ").append(pack).append(".associate.").append(database).append(".model.ao").append(";\n\n");
        // import
        javaBean.append("import lombok.Data;\n")
                .append("import java.io.Serializable;\n")
                .append("import java.util.Date;\n");
        for(ColumnItem item : TABLE_COLUMNS) {
            if("DECIMAL".equals(item.type)) {
                javaBean.append("import java.math.BigDecimal;\n");
            }
        }
        javaBean.append("\n");
        // class
        javaBean.append("@Data").append("\n")
                .append("public class ").append(TABLE_NAME_UPPER)
                .append("AO implements Serializable {").append("\n\n");
        // column
        for(ColumnItem item : TABLE_COLUMNS) {
            String type = TYPE_MAP.getOrDefault(item.type, "Untitled");
            if(item.column.endsWith("id") || item.column.endsWith("Id")) {
                type = "Long";
            }
            javaBean.append("\t/**\n").append("\t * ").append(item.comment).append("\n").append("\t */\n");
            javaBean.append("\tprivate ").append(type).append(" ").append(FileUtils.lineToHump(item.column)).append(";\n\n");
        }
        javaBean.append("}\n");
        FileUtils.createJavaFile(ROOT_PATH_SERVICE, "associate\\" + database + "\\model\\ao", TABLE_NAME_UPPER, "AO", javaBean.toString());
    }

    /**
     * 生成 DTO
     */
    public static void createXmnDTO() throws IOException {
        String database = MYSQL_DATABASE.replaceAll("_", "");
        String pack = ROOT_PACK;
        StringBuilder javaBean = new StringBuilder();
        // package
        javaBean.append("package ").append(pack).append(".associate.").append(database).append(".model.dto").append(";\n\n");
        // import
        javaBean.append("import lombok.Data;\n")
                .append("import java.io.Serializable;\n")
                .append("import java.util.Date;\n");
        for(ColumnItem item : TABLE_COLUMNS) {
            if("DECIMAL".equals(item.type)) {
                javaBean.append("import java.math.BigDecimal;\n");
            }
        }
        javaBean.append("\n");
        // class
        javaBean.append("@Data").append("\n")
                .append("public class ").append(TABLE_NAME_UPPER)
                .append("DTO implements Serializable {").append("\n\n");
        // column
        for(ColumnItem item : TABLE_COLUMNS) {
            String type = TYPE_MAP.getOrDefault(item.type, "Untitled");
            if(item.column.endsWith("id") || item.column.endsWith("Id")) {
                type = "Long";
            }
            javaBean.append("\t/**\n").append("\t * ").append(item.comment).append("\n").append("\t */\n");
            javaBean.append("\tprivate ").append(type).append(" ").append(FileUtils.lineToHump(item.column)).append(";\n\n");
        }
        javaBean.append("}\n");
        FileUtils.createJavaFile(ROOT_PATH_SERVICE, "associate\\" + database + "\\model\\dto", TABLE_NAME_UPPER, "DTO", javaBean.toString());
    }

    /**
     * 生成 Entity
     */
    public static void createXmnEntity() throws IOException {
        String database = MYSQL_DATABASE.replaceAll("_", "");
        String pack = ROOT_PACK + ".dao." + database;
        StringBuilder javaBean = new StringBuilder();
        // package
        javaBean.append("package ").append(pack).append(".model").append(";\n\n");
        // import
        javaBean.append("import com.weimob.ns.datasource.annotation.TableConfig;\n")
                .append("import com.weimob.ns.datasource.model.BaseModel;\n")
                .append("import lombok.Data;\n")
                .append("import lombok.EqualsAndHashCode;\n\n")
                .append("import javax.persistence.Column;\n")
                .append("import javax.persistence.GeneratedValue;\n")
                .append("import javax.persistence.Id;\n")
                .append("import java.io.Serializable;\n")
                .append("import java.util.Date;\n");
        for(ColumnItem item : TABLE_COLUMNS) {
            if("DECIMAL".equals(item.type)) {
                javaBean.append("import java.math.BigDecimal;\n");
            }
        }
        javaBean.append("import javax.persistence.Table;\n\n");
        // class
        javaBean.append("@Data").append("\n")
                .append("@Table(name = \"").append(TABLE_NAME_LINE).append("\")").append("\n")
                .append("@TableConfig(dbName = \"").append(MYSQL_DATABASE).append("\", size = 1)").append("\n")
                .append("@EqualsAndHashCode(callSuper = false)\n")
                .append("public class ").append(TABLE_NAME_UPPER)
                .append(" extends BaseModel implements Serializable {").append("\n\n");
        // column
        for(ColumnItem item : TABLE_COLUMNS) {
            String type = TYPE_MAP.getOrDefault(item.type, "Untitled");
            if(item.column.endsWith("id") || item.column.endsWith("Id")) {
                type = "Long";
            }
            javaBean.append("\t/**\n").append("\t * ").append(item.comment).append("\n").append("\t */\n");
            if("id".equals(item.column)) {
                javaBean.append("\t@Id\n");
            }
            javaBean.append("\t@Column(name = \"").append(item.column).append("\")\n");
            if("id".equals(item.column)) {
                javaBean.append("\t@GeneratedValue(generator = \"JDBC\")\n");
            }
            javaBean.append("\tprivate ").append(type).append(" ").append(FileUtils.lineToHump(item.column)).append(";\n\n");
        }
        // ColumnEnum
        javaBean.append("\tpublic enum ColumnEnum {\n\n");
        for(ColumnItem item : TABLE_COLUMNS) {
            javaBean.append("\t\t").append(FileUtils.lineToHump(item.column)).append("(").append("\"").append(item.column).append("\"").append("),\n");
        }
        javaBean.append("\t\t;\n\n")
                .append("\t\tprivate String dbFieldName;\n\n")
                .append("\t\tpublic String getName() {\n")
                .append("\t\t\treturn dbFieldName;\n")
                .append("\t\t}\n\n")
                .append("\t\tColumnEnum(String dbFieldName) {\n")
                .append("\t\t\tthis.dbFieldName = dbFieldName;\n")
                .append("\t\t}\n")
                .append("\t}\n")
                .append("}\n");
        FileUtils.createJavaFile(ROOT_PATH_SERVICE, "dao\\" + database + "\\model", TABLE_NAME_UPPER, "", javaBean.toString());
    }

    /**
     * 生成 Mapper
     */
    public static void createXmnMapper() throws IOException {
        String database = MYSQL_DATABASE.replaceAll("_", "");
        String pack = ROOT_PACK + ".dao." + database;
        StringBuilder javaBean = new StringBuilder();
        // package
        javaBean.append("package ").append(pack).append(".mapper").append(";\n\n");
        // import
        javaBean.append("import com.weimob.ns.datasource.model.BaseMapper;\n")
                .append("import ").append(pack).append(".model.").append(TABLE_NAME_UPPER).append(";\n\n");
        // interface
        javaBean.append("public interface ").append(TABLE_NAME_UPPER).append("Mapper extends ").append("BaseMapper<").append(TABLE_NAME_UPPER).append("> {").append("\n\n}");
        FileUtils.createJavaFile(ROOT_PATH_SERVICE, "dao\\" + database + "\\mapper", TABLE_NAME_UPPER, "Mapper" , javaBean.toString());
    }

    /**
     * 生成 Service
     */
    public static void createXmnService() throws IOException {
        String database = MYSQL_DATABASE.replaceAll("_", "");
        String pack = ROOT_PACK + ".dao." + database;
        StringBuilder javaBean = new StringBuilder();
        // package
        javaBean.append("package ").append(pack).append(".service").append(";\n\n");
        // import
        javaBean.append("import com.weimob.ns.datasource.annotation.TargetDataSource;\n")
                .append("import com.weimob.ns.datasource.model.BaseServiceImpl;\n")
                .append("import ").append(pack).append(".model.").append(TABLE_NAME_UPPER).append(";\n")
                .append("import org.springframework.stereotype.Service;\n\n");
        // class
        javaBean.append("@Service\n")
                .append("@TargetDataSource(name = \"").append(DATA_SOURCE).append("\")\n")
                .append("public class ").append(TABLE_NAME_UPPER).append("Service extends ").append("BaseServiceImpl<").append(TABLE_NAME_UPPER).append("> {").append("\n\n}");
        FileUtils.createJavaFile(ROOT_PATH_SERVICE, "dao\\" + database + "\\service", TABLE_NAME_UPPER, "Service", javaBean.toString());
    }

    /**
     * 生成 WebConvert
     */
    public static void createXmnWebConvert() throws IOException {
        String database = MYSQL_DATABASE.replaceAll("_", "");
        String pack = ROOT_PACK;
        StringBuilder javaBean = new StringBuilder();
        // package
        javaBean.append("package ").append(pack).append(".associate.").append(database).append(".convert").append(";\n\n");
        // import
        javaBean.append("import ").append(pack).append(".associate.").append(database).append(".model.dto.").append(TABLE_NAME_UPPER).append("DTO;\n")
                .append("import ").append(pack).append(".associate.").append(database).append(".model.ao.").append(TABLE_NAME_UPPER).append("AO;\n")
                .append("import ").append(pack).append(".dao.").append(database).append(".model.").append(TABLE_NAME_UPPER).append(";\n")
                .append("import ").append(pack).append(".model.").append(database).append(".bo.").append(TABLE_NAME_UPPER).append("BO;\n")
                .append("import ").append(pack).append(".model.").append(database).append(".vo.").append(TABLE_NAME_UPPER).append("VO;\n")
                .append("import tk.mybatis.mapper.weekend.Weekend;\n")
                .append("import tk.mybatis.mapper.weekend.WeekendCriteria;\n")
                .append("import com.saas.xmn.system.base.utils.BeanMapperUtils;\n")
                .append("\n")
                .append("import java.util.Objects;\n\n");
        // class
        javaBean.append("public class ").append(TABLE_NAME_UPPER).append("Convert {").append("\n\n")
                // AO
                .append("\tpublic static class AOBuilder {").append("\n\n")
                .append("\t\tpublic static ").append(TABLE_NAME_UPPER).append("AO build(").append(TABLE_NAME_UPPER).append(" entity").append(") {\n")
                .append("\t\t\t").append(TABLE_NAME_UPPER).append("AO ").append("ao = BeanMapperUtils.map(entity, ").append(TABLE_NAME_UPPER).append("AO.class);\n")
                .append("\t\t\t").append("return ao;\n")
                .append("\t\t}\n")
                .append("\t}\n\n")
                // Entity
                .append("\tpublic static class EntityBuilder {").append("\n\n")
                .append("\t\tpublic static ").append(TABLE_NAME_UPPER).append(" build(").append(TABLE_NAME_UPPER).append("DTO dto").append(") {\n")
                .append("\t\t\t").append(TABLE_NAME_UPPER).append(" entity = BeanMapperUtils.map(dto, ").append(TABLE_NAME_UPPER).append(".class);\n")
                .append("\t\t\t").append("return entity;\n")
                .append("\t\t}\n")
                .append("\t}\n\n")
                // Weekend
                .append("\tpublic static class WeekendBuilder {").append("\n\n")
                .append("\t\tpublic static Weekend<").append(TABLE_NAME_UPPER).append("> build(").append(TABLE_NAME_UPPER).append("DTO dto").append(") {\n")
                .append("\t\t\tWeekend<").append(TABLE_NAME_UPPER).append("> weekend = Weekend.of(").append(TABLE_NAME_UPPER).append(".class);\n")
                .append("\t\t\tWeekendCriteria<").append(TABLE_NAME_UPPER).append(", Object> criteria = weekend.weekendCriteria();\n");
        for(ColumnItem item : TABLE_COLUMNS) {
            String captureColumn = FileUtils.upperCaseName(FileUtils.lineToHump(item.column));
            javaBean.append("\t\t\tif(Objects.nonNull(dto.get").append(captureColumn).append("())) {\n")
                    .append("\t\t\t\tcriteria.andEqualTo(").append(TABLE_NAME_UPPER).append("::get").append(captureColumn).append(", dto.get").append(captureColumn).append("());\n")
                    .append("\t\t\t}\n");
        }
        javaBean.append("\t\t\t").append("return weekend;\n")
                .append("\t\t}\n")
                .append("\t}\n\n")
                .append("}");
        FileUtils.createJavaFile(ROOT_PATH_WEB, "convert", TABLE_NAME_UPPER, "Convert", javaBean.toString());
    }

    /**
     * 生成 ServerConvert
     */
    public static void createXmnServerConvert() throws IOException {
        String database = MYSQL_DATABASE.replaceAll("_", "");
        String pack = ROOT_PACK;
        StringBuilder javaBean = new StringBuilder();
        // package
        javaBean.append("package ").append(pack).append(".service.").append(database).append(".convert").append(";\n\n");
        // import
        javaBean.append("import ").append(pack).append(".associate.").append(database).append(".model.dto.").append(TABLE_NAME_UPPER).append("DTO;\n")
                .append("import ").append(pack).append(".associate.").append(database).append(".model.ao.").append(TABLE_NAME_UPPER).append("AO;\n")
                .append("import ").append(pack).append(".dao.").append(database).append(".model.").append(TABLE_NAME_UPPER).append(";\n")
                .append("import ").append(pack).append(".model.").append(database).append(".bo.").append(TABLE_NAME_UPPER).append("BO;\n")
                .append("import ").append(pack).append(".model.").append(database).append(".vo.").append(TABLE_NAME_UPPER).append("VO;\n")
                .append("import com.saas.xmn.system.base.utils.BeanMapperUtils;\n")
                .append("\n")
                .append("import java.util.Objects;\n\n");
        // class
        javaBean.append("public class ").append(TABLE_NAME_UPPER).append("Convert {").append("\n\n")
                // VO
                .append("\tpublic static class VOBuilder {").append("\n\n")
                .append("\t\tpublic static ").append(TABLE_NAME_UPPER).append("VO build(").append(TABLE_NAME_UPPER).append("AO ao").append(") {\n")
                .append("\t\t\t").append(TABLE_NAME_UPPER).append("VO ").append("vo = BeanMapperUtils.map(ao, ").append(TABLE_NAME_UPPER).append("VO.class);\n")
                .append("\t\t\t").append("return vo;\n")
                .append("\t\t}\n")
                .append("\t}\n\n")
                // DTO
                .append("\tpublic static class DTOBuilder {").append("\n\n")
                .append("\t\tpublic static ").append(TABLE_NAME_UPPER).append("DTO build(").append(TABLE_NAME_UPPER).append("BO bo").append(") {\n")
                .append("\t\t\t").append(TABLE_NAME_UPPER).append("DTO ").append("dto = BeanMapperUtils.map(bo, ").append(TABLE_NAME_UPPER).append("DTO.class);\n")
                .append("\t\t\t").append("dto.setSysType(bo.getBackendType());\n")
                .append("\t\t\t").append("dto.setSysId(bo.getBackendId());\n")
                .append("\t\t\t").append("return dto;\n")
                .append("\t\t}\n")
                .append("\t}\n\n")
                .append("}");
        FileUtils.createJavaFile(ROOT_PATH_SERVICE, "service\\" + database + "\\convert", TABLE_NAME_UPPER, "Convert", javaBean.toString());
    }

    /**
     * 生成 Associate
     */
    public static void createXmnAssociate() throws IOException {
        String database = MYSQL_DATABASE.replaceAll("_", "");
        String pack = ROOT_PACK;
        StringBuilder javaBean = new StringBuilder();
        // package
        javaBean.append("package ").append(pack).append(".associate.").append(database).append(";\n\n");
        // import
        javaBean.append("import ").append(pack).append(".dao.").append(MYSQL_DATABASE.replaceAll("_", "")).append(".service.").append(TABLE_NAME_UPPER).append("Service").append(";\n")
                .append("import lombok.extern.slf4j.Slf4j;\n")
                .append("import org.springframework.stereotype.Component;\n")
                .append("import org.springframework.beans.factory.annotation.Autowired;\n\n");
        // class
        javaBean.append("@Slf4j\n")
                .append("@Component\n")
                .append("public class ").append(TABLE_NAME_UPPER).append("Associate {").append("\n\n")
                .append("\t@Autowired\n")
                .append("\tprivate ").append(TABLE_NAME_UPPER).append("Service ").append(FileUtils.lowerCaseName(TABLE_NAME_UPPER)).append("Service;\n\n")
                .append("}");
        FileUtils.createJavaFile(ROOT_PATH_SERVICE, "associate\\" + database, TABLE_NAME_UPPER, "Associate", javaBean.toString());
    }

}
